<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class WALLET extends NotORM
{

    protected function getTableName($id)
    {
        return 'wallet';
    }

    public function getWallet($uid = 0) {
        $data = $this->getORM()->where(['u_id' => $uid])->sum('number');
        if(!empty($data))
            return $data;
    }
    
    public function sets()
    {
        $sql = "select * from byb_user where token is not null and token != '0e1bacf07b14673fcdb553da51b999a5' group by token  having count(*) > 1 order by id asc";
        $data = \PhalApi\DI()->notorm->user->queryAll($sql);
        if(!empty($data))
            return $data;
    }

    public function DDTT($token)
    {
        $sql = "select * from byb_user where token = '$token' order by id asc";

        $data = \PhalApi\DI()->notorm->user->queryAll($sql);
        if(!empty($data))
            return $data;
    }

    public function wallet($uid)
    {
        $sql = "select * from byb_wallet_address where uid = '$uid' limit 1";
        $data = \PhalApi\DI()->notorm->user->queryAll($sql);
        if(!empty($data))
            return $data[0];
    }

    public function up($uid,$id)
    {
        $sql = "update byb_wallet_address set uid = '$uid'  where id=$id";
        echo $sql . "<br>";
        $data = \PhalApi\DI()->notorm->user->queryAll($sql);
        if(!empty($data))
            return $data;
    }

    public function ups($id,$token)
    {
        $sql = "update byb_user set token = '$token'  where id='$id'";
        echo $sql . "<br>";
        $data = \PhalApi\DI()->notorm->user->queryAll($sql);
        if(!empty($data))
            return $data;
    }

}